<?php
//if (isset($_SESSION['username'])) {
include_once 'header.php';
require_once("conn.php");
$current_year = date("Y", time());
if (isset($_GET['year'])) {
    $year = $_GET['year'];
} else {
    $year = $current_year;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>乐知家园</title>
        <style type="text/css">
            <!--
            body,td,th {
                font-family: 微软雅黑;
                font-size: 14px;
                color: #CCCCCC;
            }
            -->
        </style>
        <SCRIPT LANGUAGE= "JavaScript">
            <!--    
            function changeYear(){
                var obj = document.getElementById("year");
                var year = obj.options[obj.selectedIndex].value;
                location.href = "packStat.php?year=" + year + "&menu=stat";
            }
            //-->
        </SCRIPT>
    </head>
    <body>
        <table width="80%" border="0" align="center" cellpadding="2" cellspacing="2" bordercolor="#FFFFFF" bgcolor="#669999">
            <tr>
                <td> 年份：
                    <select id="year" name="year" onchange="changeYear()">
                        <?php for ($y = 2012; $y < $current_year + 4; $y++) { ?>
                            <option value="<?php echo $y; ?>" <?php if ($year == $y) { ?>selected<?php } ?> ><?php echo $y; ?></option>
                        <?php } ?>
                    </select>
                </td>
            </tr>
        </table>
        <br/>
        <table width="80%" border="0" align="center" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#9999FF">
            <tr bgcolor="#666666">
                <td width="80" height="30" align="center">年龄\月份</td>
                <?php for ($m = 1; $m < 13; $m++) {
                    ?>
                    <td height="30" align="center"><?php echo $m ?></td>
                    <?php
                }
                ?>
          </tr>
            <?php
            $pack_num = array();

            for ($age = 0; $age < 6; $age++) {
                for ($m = 0; $m < 13; $m++) {
                    $pack_num[$age][$m] = 0;
                }
            }

            $sql = "SELECT count(*) AS num,age,month FROM t_pack WHERE year = " . $year . " GROUP BY age,month";
            $db = new DBC();
            $data = $db->fetchData($sql);
            if ($data != null) {
                foreach ($data as $var) {
                    $pack_num[$var['age']][$var['month']] = $var['num'];
                }
            }

            for ($age = 0; $age < 6; $age++) {
                ?>
                <tr>
                    <td height="50" bgcolor="#666666" align="center" width="16%"><?php echo $age . "-" . ($age + 1) ?>岁</td>
                    <?php
                    for ($m = 1; $m < 13; $m++) {
                        $para = "?year=" . $year . "&month=" . $m . "&age=" . $age;
                        $final_num = $pack_num[$age][$m];
                        ?>
                        <td width="7%" align="center" bgcolor="#FFFFFF"><a href="packDetail.php<?php echo $para; ?>&menu=stat"><?php
                        if ($final_num == 0) {
                            echo "0";
                        } else {
                            echo "<b>" . $final_num . "</b>";
                        }
                        ?></a></td>
                    <?php } ?>
                </tr>
            <?php } ?>
    </table>
        <p>&nbsp;</p>
    </body>
</html>
<?php
include_once 'footer.php';
//} else {
//    header("login.php");
//}
?>
